/**
* @file				main.c 
* @author  		Sachintha Wijetunge
* @version 		1.0
* @date    		December 06, 2014
* @brief   		main Code for PIR and Buzzer.
*/

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "arduino.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
int pirpin = 9;
int ledpin = 5;
int buzzerpin = 6;
int pushpin = 11;
int password;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/


/**
* @brief	The setup() function will only run once, after each powerup or reset of the board. Use it to initialize variables, pin modes, start using libraries, etc.
* @param	None
* @retval	None
*/
void setup()
{
	// Define PIN modes
	pinMode(pirpin, INPUT); // PIR 
	pinMode(ledpin, OUTPUT); // LED
	digitalWrite(ledpin, LOW); 
	pinMode(buzzerpin, OUTPUT); // Buzzer
	digitalWrite(buzzerpin, LOW);
	pinMode(pushpin, INPUT); // PushButton
}
/**
* Clear/ Reset buzzer and LED to default
*
*/
void reset(void)
{
	digitalWrite(ledpin, LOW); // Set LED low
	digitalWrite(buzzerpin, LOW); // Set Buzzer low
}


/**
* @brief	The loop() function does loop consecutively, allowing your program to change and respond. Use it to actively control the board.
* @param	None
* @retval	None
*/


void loop()
{
	int PIRstatus = digitalRead(pirpin);
	while(pushpin == LOW) // Check Push Button Status
	{
	if(PIRstatus == HIGH){ // Check PIR status
		ledpin = HIGH; // Set LED High
		buzzerpin = HIGH; // Set buzzer  high
		}
	}
	reset();
}

/**
* @brief	Template main function
* @param	None
* @retval	None
*/
int main() 
{
	platform_config();
	setup();
	while(1) {
		loop();
	}
	
}
